// https://leetcode.cn/problems/maximum-subarray/description/?envType=study-plan-v2&envId=top-interview-150

class Solution {
public:
    int maxSubArray(vector<int>& nums) {
        int curMax = nums[0];
        int globalMax = nums[0];

        for (int i = 1; i < nums.size(); i++) {
            curMax = max(nums[i], nums[i] + curMax);
            globalMax = max(curMax, globalMax);
        }
        return globalMax;
    }
};